package edu.sias.hyzn.controller;

import edu.sias.common.core.controller.BaseController;
import edu.sias.common.core.domain.AjaxResult;
import edu.sias.common.core.page.TableDataInfo;
import edu.sias.hyzn.service.impl.DoctorService;
import edu.sias.hyzn.vo.DoctorInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/hyzn/doctor")
public class DoctorController extends BaseController {

    private final DoctorService doctorService;

    @Autowired
    public DoctorController(DoctorService doctorService) {
        this.doctorService = doctorService;
    }

    @GetMapping("/list")
    public TableDataInfo doctorList(DoctorInfo doctorInfo){
        startPage();
        return getDataTable(doctorService.selectDoctorList(doctorInfo));
    }

    @GetMapping("/me")
    public AjaxResult getDoctorInfo(){
        return success(doctorService.getDoctorInfo());
    }

    @PostMapping("/info")
    public AjaxResult insertDoctorInfo(@RequestBody DoctorInfo doctorInfo){
        if (doctorInfo == null || doctorInfo.getClassify() == null || doctorInfo.getSpeciality() == null){
            AjaxResult.error(400, "必要参数不能为空");
        }
        return success(doctorService.insertDoctorInfo(doctorInfo));
    }

    @PutMapping("/info")
    public AjaxResult updateDoctorInfo(@RequestBody DoctorInfo doctorInfo){
        return toAjax(doctorService.updateDoctorInfo(doctorInfo));
    }
}
